package com.salou.cellar.activity;

import android.app.Activity;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.salou.cellar.R;
import com.salou.cellar.contentprovider.CellarContentProvider;
import com.salou.cellar.dto.Bottle;

public class BottleDetailActivity extends Activity implements OnClickListener {

	private CellarContentProvider ccp;
	private Bottle bottle;
	private Button mBackButton;
	private TextView nomCru;
	private TextView millesime;
	private TextView country_label;
	private TextView area_label;
	private TextView label;
	private TextView boire_avant;
	private TextView garde_min;
	private TextView garde_max;
	private TextView quantite_courante;
	private TextView garde_optimum;
	private TextView prix;
	private TextView cote;
	private TextView comment;
	private TextView date_achat;
	private TextView lieu_achat;
	private TextView nom;
	private TextView coordY;
	private TextView coordZ;
	private TextView coordX;
	private TextView suggestion;
	private TextView subregion_label;
	private int id;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ccp = new CellarContentProvider(getApplicationContext());
		setContentView(R.layout.bottle_detail);
		this.id = getIntent().getExtras().getInt("_id");
		try {
			initDisplay();
			this.bottle = ccp.getBottle(id);
			showDisplay();
		} catch (Exception e) {
			dispose(RESULT_CANCELED);
		}
	}

	private void dispose(int result) {
		// back button clicked
		setResult(result);
		this.finish();
	}

	private void initDisplay() {
		this.mBackButton = (Button) findViewById(R.id.back_button);
		this.mBackButton.setOnClickListener(this);
	}

	private void showDisplay() {
		nomCru = (TextView) findViewById(R.id.nom_cru);
		nomCru.setText(bottle.getNomCru());
		millesime = (TextView) findViewById(R.id.millesime);
		millesime.setText(bottle.getMillesime());
		country_label = (TextView) findViewById(R.id.country_label);
		country_label.setText(bottle.getCountry_label());
		area_label = (TextView) findViewById(R.id.area_label);
		area_label.setText(bottle.getLabel());
		subregion_label = (TextView) findViewById(R.id.subregion_label);
		subregion_label.setText(bottle.getSubregion_label());
		label = (TextView) findViewById(R.id.label);
		label.setText(bottle.getLabel());
		boire_avant = (TextView) findViewById(R.id.boire_avant);
		boire_avant.setText(bottle.getBoire_avant());
		garde_min = (TextView) findViewById(R.id.garde_min);
		garde_min.setText(bottle.getGarde_min());
		garde_max = (TextView) findViewById(R.id.garde_max);
		garde_max.setText(bottle.getGarde_max());
		garde_optimum = (TextView) findViewById(R.id.garde_optimum);
		garde_optimum.setText(bottle.getGarde_optimum());
		quantite_courante = (TextView) findViewById(R.id.quantite_courante);
		quantite_courante.setText(bottle.getQuantite_courante());
		prix = (TextView) findViewById(R.id.prix);
		prix.setText(bottle.getPrix());
		cote = (TextView) findViewById(R.id.cote);
		cote.setText(bottle.getCote());
		comment = (TextView) findViewById(R.id.comment);
		comment.setText(bottle.getComment());
		suggestion = (TextView) findViewById(R.id.suggestion);
		suggestion.setText(bottle.getSuggestion());
		date_achat = (TextView) findViewById(R.id.date_achat);
		date_achat.setText(bottle.getDate_achat());
		lieu_achat = (TextView) findViewById(R.id.lieu_achat);
		lieu_achat.setText(bottle.getLieu_achat());
		nom = (TextView) findViewById(R.id.nom);
		nom.setText(bottle.getNomCasier());
		coordX = (TextView) findViewById(R.id.coordX);
		coordX.setText(bottle.getCoordX());
		coordY = (TextView) findViewById(R.id.coordY);
		coordY.setText(bottle.getCoordY());
		coordZ = (TextView) findViewById(R.id.coordZ);
		coordZ.setText(bottle.getCoordZ());
	}

	@Override
	public void onClick(View v) {
		// back button clicked
		setResult(RESULT_OK);
		this.finish();
	}

}
